/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2022 All Rights Reserved.
 */
package com.example.spider.config;

import com.example.spider.task.Task;
import com.example.spider.util.BitSetModule;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import org.shoulder.core.util.JsonUtils;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author lym
 */
@Component
@Configuration
public class DefaultConfigurationInitializer implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

    private static final boolean isWin = System.getProperty("os.name").toLowerCase().contains("win");


    @Override
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        Task.subTypes.forEach((n, clazz) -> JsonUtils.getInstance().registerSubtypes(new NamedType(clazz, n)));

        System.setProperty("spider.storage.filePath.default", System.getProperty("user.home") + "/spider");
        JsonUtils.getInstance().registerModule(BitSetModule.INSTANCE);
    }
}